<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useMemberStore } from "@/store/member";
const store = useMemberStore();
const isLogin = ref<boolean>()
onMounted(() => {
  isLogin.value = !!store.profile.token
  const pageStack = getCurrentPages()
  // 获取最后一个一个页面的页面实例
  const prevPage = pageStack[pageStack.length - 1]
  if (!isLogin.value) {
    console.log('authorization跳转页面了');
    uni.showToast({ title: '请先登录', icon: 'none' })
    uni.redirectTo({
      url: '/pages/login/index?redirectURL=' + prevPage.route
    })
  }
})
</script>

<template>
  <slot v-if="isLogin"></slot>
</template>

<style lang="scss" scoped></style>
